package com.ruoyi.project.inspection.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.inspection.domain.VehicleImg;
import com.ruoyi.project.inspection.service.IVehicleImgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 车辆行驶证图片Controller
 *
 * @author ruoyi
 * @date 2020-07-13
 */
@RestController
@RequestMapping("/inspection/vehicleImg")
public class VehicleImgController extends BaseController {
    @Autowired
    private IVehicleImgService vehicleImgService;

    /**
     * 查询车辆行驶证图片列表
     */
    @PreAuthorize("@ss.hasPermi('inspection:vehicleImg:list')")
    @GetMapping("/list")
    public TableDataInfo list(VehicleImg vehicleImg) {
        startPage();
        List<VehicleImg> list = vehicleImgService.selectVehicleImgList(vehicleImg);
        return getDataTable(list);
    }

    /**
     * 导出车辆行驶证图片列表
     */
    @PreAuthorize("@ss.hasPermi('inspection:vehicleImg:export')")
    @Log(title = "车辆行驶证图片", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(VehicleImg vehicleImg) {
        List<VehicleImg> list = vehicleImgService.selectVehicleImgList(vehicleImg);
        ExcelUtil<VehicleImg> util = new ExcelUtil<VehicleImg>(VehicleImg.class);
        return util.exportExcel(list, "vehicleImg");
    }

    /**
     * 获取车辆行驶证图片详细信息
     */
    @PreAuthorize("@ss.hasPermi('inspection:vehicleImg:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(vehicleImgService.selectVehicleImgById(id));
    }

    /**
     * 新增车辆行驶证图片
     */
    @PreAuthorize("@ss.hasPermi('inspection:vehicleImg:add')")
    @Log(title = "车辆行驶证图片", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VehicleImg vehicleImg) {
        return toAjax(vehicleImgService.insertVehicleImg(vehicleImg));
    }

    /**
     * 修改车辆行驶证图片
     */
    @PreAuthorize("@ss.hasPermi('inspection:vehicleImg:edit')")
    @Log(title = "车辆行驶证图片", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VehicleImg vehicleImg) {
        return toAjax(vehicleImgService.updateVehicleImg(vehicleImg));
    }

    /**
     * 删除车辆行驶证图片
     */
    @PreAuthorize("@ss.hasPermi('inspection:vehicleImg:remove')")
    @Log(title = "车辆行驶证图片", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(vehicleImgService.deleteVehicleImgByIds(ids));
    }
}
